<template>
	<view class="content">

		<view class="tabs">
			<u-tabs :list="list2" lineWidth="30" lineColor="#fcaf47"
				itemStyle="padding-left:10rpx;padding-right:-50rpx;width:110rpx; height:80rpx; " @click="click"
				:activeStyle="{
		            color: '#101010 100%',
		            fontWeight: 'bold',
		            transform: 'scale(1.05)',
					
		        }" :inactiveStyle="{
		            color: '#9B9B9B 100%',
		            transform: 'scale(1)'
		        }"></u-tabs>
		</view>
		<view class="buttomcard">
			<view @click="gomoyvact()">
				<act-card_heng v-show="isTabs.name==0" v-for="(item,index) in AllData" :item="item"
					:imgId="item.img_id"
					:eventname="item.event_name">
				</act-card_heng>

				<act-card_heng v-show="isTabs.name==1" v-for="(item,index) in pendingData" :item="item"
					:imgId="item.img_id"
					:eventname="item.event_name">
				</act-card_heng>


				<act-card_heng v-show="isTabs.name==2" v-for="(item,index) in overActData" :item="item"
					:imgId="item.img_id"
					:eventname="item.event_name">
				</act-card_heng>

				<act-card_heng v-show="isTabs.name==3" v-for="(item,index) in notOverData" :item="item"
					:imgId="item.img_id"
					:eventname="item.event_name">
				</act-card_heng>


				<act-card_heng v-show="isTabs.name==3" v-for="(item,index) in notSignData" :item="item"
					:imgId="item.img_id"
					:eventname="item.event_name">
				</act-card_heng>
			</view>
		</view>

	</view>
</template>

<script>
	import actCard_heng from '../../components/actCard_heng.vue'
	import {
		mapState,
		mapMutations

	} from 'vuex'
	export default {
		components: {
			actCard_heng,
		},
		data() {
			return {
				AllData: [], //全部的活动
				pendingData: [], //正在审核的活动
				overActData: [], //完结的活动
				notOverData: [], //未完结的活动
				notSignData: [], //未签到的
				// 当前样式
				target: 0,
				// 当前item位置
				thisindex: 0,
				user_Id: this.$store.state.userInfo.id,
				imgUrl: 'https://www.codingyt.com/getImgFast/',
				act_Id: '',
				actData: [],
				isTabs: {
					name: '',
				},
				list2: [{
						name: '全部', //设置活动的状态
					},
					{
						name: '审核中',
					},
					{
						name: '已完结',
					},
					{
						name: '未完结',
					},
					{
						name: '未签到',
					},
				],
				navtop: {
					title: 'XXX',
					color: '#000000'
				},
			}
		},
		methods: {
			click(item) {
				
				this.isTabs.name = item.index;
			},
			gomoyvact() {
				uni.navigateTo({
					url: '/pages/index/act',
				});
			},
			getpendingAct() {
				let userId = this.user_Id
				let actId = this.act_Id
				let that = this
				let eventId = '';
			
				uni.request({
					url: 'https://www.codingyt.com/club/userEvent/select',
					data: {
						userId: that.user_Id,
						role: 'pending',
						eventId: null,
					},
					success: (res) => {						
						that.pendingData = res.data.data
					}
				});
			},
			getAllAct() {
				let that = this
				uni.request({
					url: 'https://www.codingyt.com/club/userEvent/select',
					data: {
						userId: that.user_Id,
						role: null,
						eventId: null,
					},
					success: (res) => {
						//that.actData = res.data.data
						that.AllData = res.data.data
						var tmpData = res.data.data
						//获取完结和未完结的活动出来
						var overActData = []
						var notOverData = []
						var notSignData = []
						for (var i = 0; i < tmpData.length; i++) {
							if (that.checkIsOver(tmpData[i].start_time, tmpData[i].end_time) == 2) {
								overActData.push(tmpData[i]);
							}
							if (that.checkIsOver(tmpData[i].start_time, tmpData[i].end_time) != 2) {
								notOverData.push(tmpData[i]);
							}
							if (tmpData[i].sign_in != true) {
								notSignData.push(tmpData[i]);
							}
						}
						//进行数据赋值
						that.overActData=overActData
						that.notOverData=notOverData
						that.notSignData=notSignData
					}
				})
			},
			//检查是不是已经结束了 我们的活动
			checkIsOver(start_time, end_time) {
				var startTime = Date.parse(start_time);
				var endTime = Date.parse(end_time);
				var curTime = new Date().getTime() //获取当前的时间戳
				if (startTime - curTime > 0) {
					return 1; //代表还未开始
				}
				if (endTime - curTime < 0) {
					return 2; //代表已经结束
				}
				return 0; //代表正常进行
			}
		},
		onLoad() {
			//获取审核中的活动
			this.getpendingAct()
			//获取全部的活动()
			this.getAllAct();
		},
	}
</script>

<style scoped lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";

	.bottomCard {}

	.tabs {
		margin-top: 1%;
		left: 30rpx;
		color: rgba(16, 16, 16, 100);
		font-size: 48rpx;
		position: relative;
	}

	.actCard {
		margin-top: 1%;
		left: 0rpx;
		position: relative;
	}
</style>
